﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Odbc;
using DBManager;
using LogManager;

namespace DataBaseConnectTest
{
    public partial class Form1 : Form
    {
        private string connecting = @"DSN=OracleTest;UID=knrt;PWD=knrt;";
        private string mic_connect = @"";
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int count = getTableInfo();
            label1.Text = $"一共查询了 {count.ToString()}个";
        }

        public int getTableInfo()
        {

            //参考网站：https://blog.csdn.net/u012593344/article/details/51406624 已经收藏到CHOME浏览器的学习文件夹--orcale 目录下。
            //这里会报错：体系结构不正确需要将项目平台目标改成x64 （因为我安装的是64位的驱动）
            OdbcConnection odbcconn = new OdbcConnection(connecting);
            odbcconn.Open();
            string strComm = "select * from pay.mk_ef_knrt_drug";
            OdbcDataAdapter odbcda = new OdbcDataAdapter(strComm, odbcconn);
            DataSet ds = new DataSet();
            odbcda.Fill(ds);
            DataTable dt = new DataTable();
            dt = ds.Tables[0];
            odbcconn.Close();
            odbcconn.Dispose();
            return dt.Rows.Count;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DBResult result = DBReader.GetDataTable("HISDB1", "select * from pay.mk_ef_knrt_drug");
            if (result.bSucceedFlag)
            {
                label1.Text = $"一共查询了 {result.iRowCount.ToString()}个";
            }
            else
            {
                Logger.Error(result.strMessage);
            }
        }
    }
}
